SCRIPT=$(readlink -f $0)
WD=`dirname $SCRIPT`
ROOT_DIR=${WD}/opencv-4.10.0

BUILD_DIR=${ROOT_DIR}/build_armv8_android
INSTALL_DIR=${WD}/armv8_android_opencv-4.10.0

rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"

NDK_ROOT=/home/ly/Android/Sdk/ndk/24.0.8215888
#ANDROID_ABI=${ANDROID_ABI:-"armeabi-v7a with NEON"}
ANDROID_ABI=${ANDROID_ABI:-"arm64-v8a"}
if [ "${ANDROID_ABI}" = "armeabi" ]; then
    API_LEVEL=19
else
    API_LEVEL=21
fi
cmake -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
      -DCMAKE_TOOLCHAIN_FILE="${NDK_ROOT}/build/cmake/android.toolchain.cmake" \
      -DANDROID_NDK="${NDK_ROOT}" \
      -DANDROID_NATIVE_API_LEVEL=${API_LEVEL} \
      -DANDROID_ABI="${ANDROID_ABI}" \
      -D WITH_CUDA=OFF \
      -D WITH_MATLAB=OFF \
      -D BUILD_ANDROID_EXAMPLES=OFF \
      -D BUILD_DOCS=OFF \
      -D BUILD_PERF_TESTS=OFF \
      -D BUILD_TESTS=OFF \
      -D WITH_PROTOBUF=OFF \
      -DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}" \
      ..

make -j8
make install